package com.pro.springbootshop.service.impl;
import com.pro.springbootshop.entity.FlashActivity;
import com.pro.springbootshop.entityExtend.FlashActivityReturn;
import com.pro.springbootshop.mapper.FlashActivityMapper;
import com.pro.springbootshop.service.FlashActivityService;
import com.pro.springbootshop.util.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FlashActivityServiceImpl implements FlashActivityService {
    @Autowired
    TokenUtil tokenUtil;
    public FlashActivityMapper flashActivityMapper;
    @Autowired
    public void setUserMapper (FlashActivityMapper flashActivityMapper) {
        this.flashActivityMapper = flashActivityMapper;
    }
    @Override
    public String saveFlashActivity(FlashActivity flashActivity) {
        flashActivity.setFlashActivityState(0);
        int i=flashActivityMapper.insert(flashActivity);
        if(i>0){
            return "提交成功";
        }else {
            return "提交失败";
        }
    }
    @Override
    public FlashActivity getFlashActivityById(Integer flashActivityId) {
        FlashActivity flashActivity=flashActivityMapper.getFlashActivityById(flashActivityId);
        return flashActivity;
    }
    @Override
    public FlashActivityReturn getAllFlashActivity(Integer page, Integer limit) {
        int pageNo=(page-1)*limit;
        int total=flashActivityMapper.selectCount(null);
        List<FlashActivity> flashActivityList=flashActivityMapper.getAllFlashActivity(pageNo,limit);
        return new FlashActivityReturn(flashActivityList,total);
    }

    @Override
    public FlashActivityReturn sellerGetAllFlashActivity(Integer page, Integer limit, String sellerId) {

        int pageNo=(page-1)*limit;
        int total=flashActivityMapper.selectCount(null);
        List<FlashActivity> flashActivityList=flashActivityMapper.sellerGetAllFlashActivity(pageNo,limit,sellerId);
        return new FlashActivityReturn(flashActivityList,total);
    }


    @Override
    public String changeFlashActivity(Integer flashActivityId,Integer flashActivityState) {
        FlashActivity flashActivity=flashActivityMapper.selectById(flashActivityId);
        flashActivity.setFlashActivityState(flashActivityState);
        int i=flashActivityMapper.updateById(flashActivity);
        if(i>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
    @Override
    public String changeFlashActivityWaresNumber(Integer flashActivityId,Integer waresNumber) {
        FlashActivity flashActivity=flashActivityMapper.selectById(flashActivityId);
        flashActivity.setWaresNumber(waresNumber);
        int i=flashActivityMapper.updateById(flashActivity);
        if(i>0){
            return "修改成功";
        }else {
            return "修改失败";
        }
    }
}